class PairSet:

    def __init__(self):
        """Represents a pairing elements of two sets."""
        self.s0match = {}
        self.s1match = {}
    
    def pair (self, a, b):
        """Establishes a pairing between elements a (of the first set) 
        and b (of the second set)."""
        if a is None: 
            assert (b is not None)
            del self.s1match[b]
        elif b is None: 
            del self.s0match[a]
        else:
            self.s0match[a]=b
            self.s1match[b]=a
        
    def setpairs (self, pairs):
        """Establishes pairing between all pairs in the given list pairs"""
        for a,b in pairs: self.pair(a,b)
        
    def second (self, a):
        """Returns the pair of element a of the first set. None if no pair."""
        if a in self.s0match: return s0match[a]
        return None
    
    def first (self, b):
        """Returns the pair of element b of the second set. None if no pair."""
        if b in self.s1match: return s1match[b]
        return None

    def attachedfirst (self):
        """Returns the set of all elements from the first set which are attached"""
        return set(self.s0match.keys())
        
    def attachedsecond (self):
        """Returns the set of all elements from the second set which are attached"""
        return set(self.s1match.keys())

